﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

using MSO = Microsoft.Office.Core;
using OL = Microsoft.Office.Interop.Outlook;

using ConvergensInterfaces;

namespace ConvergensDominoConnector
{
    public class CDCOMailItemCommandBarButtonEvents : CDCOCommandBarButtonEvents
    {
        private OL.Application application;

        public CDCOMailItemCommandBarButtonEvents(OL.Application application)
        {
            this.application = application;
        }

        public void Journalize(MSO.CommandBarButton cmdBarbutton, ref bool cancel)
        {
            try
            {
                //Button from Inspector window
                OL.MailItem selectedItem = (OL.MailItem)ItemSelector.ValidateActiveInspectorItem(this.application);
                DominoConnector.Default.journalizeMailItem(selectedItem);
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                if (ex.ErrorCode == -2147467259)
                {
                    //suppress - user cancel
                    return;
                }

                MessageBox.Show(ex.Message, "CDCO - Journaliser", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

            }
            catch (ApplicationException aex)
            {
                MessageBox.Show(aex.Message, "CDCO - Journaliser", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "CDCO - Journaliser", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
    }
}
